<?php

define('KC_INDEX',True);

require_once '../global.php';

/**

	创建内容页

	@param string $listid: 列表
	@param int    $kid   : 要生成的id
	@param int    $pid   : 第?页
	@param int    $is    : 生成或是返回值？1返回值
	@return string

*/
function king_def(){
	global $king;
	$king->load('portal');

	$listid=kc_get('listid',2,1);
	$time=kc_get('time',2);
	if(empty($time)) $time='900';
	$cachepath="gx/".$listid;
	//$cachepath2="gx/".$listid.'home';
	

	if(!$block=$king->cache->get($cachepath,time()-$time)){
		$data=$king->db->getRows_one("select kid,ktitle,listid,kkeywords from %s__article where nshow='0' and listid=".$listid." order by kid asc");
		if(empty($data)){
			$data['ktitle']='已经更新完毕';
		}else{
			if(!empty($data['kid'])){
				$king->db->update('%s__article',array('nshow'=>'1','nlastdate'=>time(),'ndate'=>time()),'kid='.$data['kid']);
				$keyk=$data['kkeywords'];
						$keyk=str_replace("，",",",$keyk); 
						$array=explode(',',$keyk);
						foreach($array as $rs){
							$king->db->update('%s_key',array('nshow'=>'1'),"ktitle='".$rs."' and nshow=0");
						}
				//$king->portal->createPage($data['listid'],$data['kid'],'1');
				$king->cache->put($cachepath,'最新更新：'.$data['ktitle']);
			}
		}
	}


	//if(!$blockto=$king->cache->get($cachepath2,time()-'3600')){
		//$king->portal->createList('1');
		//$king->portal->createList($listid);
		//$king->cache->put($cachepath2,'最新更新：'.date("Y-m-d H:i:s"));
	//}


	echo '<!--'.$block.$blockto.'-->';

	

}



?>